﻿using DNFImagePacks2Manager.Helpers;
using System.IO;

namespace DNFImagePacks2Manager.NPK
{
    public class ImageType
    {
        public int TypeCode { get; set; }

        public string TypeName(int version) => GetTypeName(TypeCode, version);

        public ImageType(BinaryReader reader)
        {
            byte[] typeCodeBytes = reader.ReadBytes(4);
            TypeCode = ByteHelper.Bytes2Int(typeCodeBytes);
        }

        public ImageType(int type)
        {
            TypeCode = type;
        }

        public byte[] GetBytes()
        {
            return ByteHelper.Int2Bytes(TypeCode);
        }

        public void SetBGRA8888()
        {
            TypeCode = 0x10;
        }


        private static string GetTypeName(int type, int version)
        {
            switch (type)
            {
                case 0x11:
                    return "指向型";
                case 0x12:
                    return "DDS-FXT1";
                case 0x13:
                    return "DDS-FXT3";
                case 0x14:
                    return "DDS-FXT5";
                case 0x10:
                    return "ARGB8888";
                case 0x0F:
                    return "ARGB4444";
                case 0x0E:
                    if (version == 4 || version == 6)
                    {
                        return "索引颜色";
                    }
                    else
                    {
                        return "ARGB1555";
                    }
            }

            if (type > 0x11)
            {
                return $"DDS-{type}";
            }
            else
            {
                return $"{type}";
            }
        }
    }
}
